<!DOCTYPE html>
<html>
<head>
    <title>Date axis</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" >

    <link href="../../content/shared/styles/examples-offline.css" rel="stylesheet">
    <link href="../../../styles/kendo.dataviz.min.css" rel="stylesheet">

    <script src="../../../js/jquery.min.js"></script>
    <script src="../../../js/kendo.dataviz.min.js"></script>
    <script src="../../content/shared/js/console.js"></script>
</head>
<body>
    <a class="offline-button" href="../index.html">Back</a>
    
        <div id="example" class="k-content">
            <div class="chart-wrapper">
                <div id="chart"></div>
            </div>
            <div class="configuration-horizontal">
                <div class="config-section">
                <span class="configHead">Base date unit</span>
                <ul class="options">
                    <li>
                        <input id="baseUnitAuto" name="baseUnit"
                                type="radio" value="" autocomplete="off" />
                        <label for="baseUnitAuto">Automatic (default)</label>
                    </li>
                    <li>
                        <input id="baseUnitYears" name="baseUnit"
                                type="radio" value="years" autocomplete="off" />
                        <label for="baseUnitYears">Years</label>
                    </li>
                    <li>
                        <input id="baseUnitMonths" name="baseUnit"
                                type="radio" value="months" autocomplete="off" />
                        <label for="baseUnitMonths">Months</label>
                    </li>
                    <li>
                        <input id="baseUnitWeeks" name="baseUnit"
                                type="radio" value="weeks" checked="checked" autocomplete="off" />
                        <label for="baseUnitWeeks">Weeks</label>
                    </li>
                    <li>
                        <input id="baseUnitDays" name="baseUnit"
                                type="radio" value="days" autocomplete="off" />
                        <label for="baseUnitDays">Days</label>
                    </li>
                </ul>
                </div>
                <div class="config-section">
                <span class="configHead">Aggregate function</span>
                <ul class="options">
                    <li>
                        <input id="aggregateMax" name="aggregate"
                                type="radio" value="max" autocomplete="off" />
                        <label for="aggregateMax">Max (default)</label>
                    </li>
                    <li>
                        <input id="aggregateMin" name="aggregate"
                                type="radio" value="min" autocomplete="off" />
                        <label for="aggregateMin">Min</label>
                    </li>
                    <li>
                        <input id="aggregateSum" name="aggregate"
                                type="radio" value="sum" autocomplete="off" />
                        <label for="aggregateSum">Sum</label>
                    </li>
                    <li>
                        <input id="aggregateAvg" name="aggregate"
                                type="radio" value="avg" checked="checked" autocomplete="off" />
                        <label for="aggregateAvg">Avg</label>
                    </li>
                    <li>
                        <input id="aggregateCount" name="aggregate"
                                type="radio" value="count" autocomplete="off" />
                        <label for="aggregateCount">Count</label>
                    </li>
                </ul>
                <p>Custom aggregate functions are supported.</p>
                </div>
            </div>
            <script>
                var stats = [
                    { value: 30, date: new Date("2011/12/20") },
                    { value: 50, date: new Date("2011/12/21") },
                    { value: 45, date: new Date("2011/12/22") },
                    { value: 40, date: new Date("2011/12/23") },
                    { value: 35, date: new Date("2011/12/24") },
                    { value: 40, date: new Date("2011/12/25") },
                    { value: 42, date: new Date("2011/12/26") },
                    { value: 40, date: new Date("2011/12/27") },
                    { value: 35, date: new Date("2011/12/28") },
                    { value: 43, date: new Date("2011/12/29") },
                    { value: 38, date: new Date("2011/12/30") },
                    { value: 30, date: new Date("2011/12/31") },
                    { value: 48, date: new Date("2012/01/01") },
                    { value: 50, date: new Date("2012/01/02") },
                    { value: 55, date: new Date("2012/01/03") },
                    { value: 35, date: new Date("2012/01/04") },
                    { value: 30, date: new Date("2012/01/05") }
                ];

                function createChart() {
                    $("#chart").kendoChart({
                        title: {
                            text: "Units sold"
                        },
                        dataSource: {
                            data: stats
                        },
                        series: [{
                            type: "line",
                            aggregate: "avg",
                            field: "value",
                            categoryField: "date"
                        }],
                        categoryAxis: {
                            baseUnit: "weeks"
                        }
                    });
                }

                $(document).ready(createChart);
                $("#example").bind("kendo:skinChange", createChart);
                $(".configuration-horizontal").bind("change", refresh);

                function refresh() {
                    var chart = $("#chart").data("kendoChart"),
                        series = chart.options.series,
                        categoryAxis = chart.options.categoryAxis,
                        baseUnitInputs = $("input:radio[name=baseUnit]"),
                        aggregateInputs = $("input:radio[name=aggregate]");

                    for (var i = 0, length = series.length; i < length; i++) {
                        series[i].aggregate = aggregateInputs.filter(":checked").val();
                    };

                    categoryAxis.baseUnit = baseUnitInputs.filter(":checked").val();

                    chart.refresh();
                }
            </script>
            <style scoped>
                .chart-wrapper, .chart-wrapper .k-chart {
                    height: 300px;
                }
            </style>
        </div>

</body>
</html>
